package cn.stylefeng.guns.czlm.service;

import cn.hutool.core.bean.BeanUtil;
import cn.stylefeng.guns.core.common.page.LayuiPageFactory;
import cn.stylefeng.guns.czlm.entity.TbCategory;
import cn.stylefeng.guns.czlm.mapper.TbCategoryMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 类目
 * @Author: LiJiaJun
 * @Date: 19-4-29 上午 11:05
 * @Version 1.0
 */
@Service
public class TbCategoryService extends ServiceImpl<TbCategoryMapper, TbCategory> {

    @Resource
    private TbCategoryMapper tbCategoryMapper;
  public   List<TbCategory> TbCategoryList(){//查询全部
        return tbCategoryMapper.TbCategoryList();
    }

    /**
     * 分页查询
     * @return
     */
    public Page<Map<String, Object>> findTbCategory(){
        Page page = LayuiPageFactory.defaultPage();
        return this.tbCategoryMapper.findTbCategoryAll(page);
    }

    /**
     * 删除
     * @param LeiId
     * @return
     */
    public int delCat(Long LeiId){
        return  tbCategoryMapper.deleteById(LeiId);
    }

    /**
     * 增加
     * @param tbCategory
     * @return
     */
    public int addCat(TbCategory tbCategory){
        return tbCategoryMapper.addCat(tbCategory);
    }

    /**
     * 修改
     * @param tbCategory
     * @return
     */
    public boolean updCat(TbCategory tbCategory){
        TbCategory tbCategorys=new TbCategory();
        BeanUtil.copyProperties(tbCategory,tbCategorys);
        return this.updateById(tbCategorys);
    }


    /**
     * 查询类目级别
     * @return
     */
    public List<TbCategory>findLevel(){
        return tbCategoryMapper.upLevelList();
    }

    /**
     * 查询类目级别
     * @return
     */
    public List<TbCategory>findLevels(){
        return tbCategoryMapper.upLevelLists();
    }

    /**
     * 查询类目下商品数量
     * @return
     */
    public List<Lists> findLists(){
        return tbCategoryMapper.Lists();
    }

}
